<?php

class Hydrum_Application extends Zend_Application
{
    /**
     * Set application options
     *
     * @param  array $options
     * @throws Zend_Application_Exception When no bootstrap path is provided
     * @throws Zend_Application_Exception When invalid bootstrap information are provided
     * @return Zend_Application
     */
    public function setOptions(array $options)
    {
        if (isset($options['applications'])) {
            $paths = explode(PATH_SEPARATOR, get_include_path());

            $paths += array_reverse($options['applications']);

            set_include_path(implode(PATH_SEPARATOR, $paths));

            if (!isset($options['bootstrap'])) {
                $options['bootstrap']['class'] = 'Bootstrap';

                foreach ($options['applications'] as $path) {
                    $file = $path . DS . 'Bootstrap.php';

                    if (file_exists($file)) {
                        $options['bootstrap']['path'] = $file;
                    }
                }

            }
        }
        
        if(isset($options['pluginpaths']))
        {
           $options['pluginLoader'] = new Hydrum_Loader_PluginLoader($options['pluginpaths']);    
        }

        parent::setOptions($options);
    }

    public static function formatCode($code)
    {
        $code = explode('-', $code);

        foreach ($code as & $word) {
            $word = ucfirst($word);
        }

        return implode('', $code);
    }
}
